package com.iwown.sample4GApi.service;

import com.google.protobuf.InvalidProtocolBufferException;
import com.iwown.sample4GApi.protobuf.PhoneBook;
import com.iwown.sample4GApi.utils.MyDateTimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OldAlarmDataParser implements IDataParser {
    private static final Logger log = LoggerFactory.getLogger(OldAlarmDataParser.class);

    @Override
    public void DataParse(byte[] payload) {
        PhoneBook.PhoneBookConfirm alarmPhonebook = null;
        try {
            alarmPhonebook = PhoneBook.PhoneBookConfirm.parseFrom(payload);
        } catch(InvalidProtocolBufferException ex) {
            ex.printStackTrace();
            return;
        }
        if(alarmPhonebook.hasAlarminfo()) {
            PhoneBook.PhoneAlarminfo alarmInfo = alarmPhonebook.getAlarminfo();
            if(alarmInfo.hasSleepstate()){
                String alarmTime = MyDateTimeUtils.convert2DateTimeString(alarmInfo.getTimeStamp().getDateTime().getSeconds());
                log.info(String.format("sleep alarm time:%s",alarmTime));
            }
        }
    }
}
